// 封装分类相关业务
import { ref, watch } from 'vue'
import { getCategoryAPI } from '@/apis/category'
import { useRoute } from 'vue-router'

export const useCategory = () => {
  const categoryData = ref([])
  const route = useRoute()
  const getCategory = async () => {
    const res = await getCategoryAPI(route.params.id)
    categoryData.value = res.result
  }

  watch(
    () => route.fullPath,
    () => {
      if(route.name !== 'Category') return
      getCategory()
    },
    {
      immediate: true
    }
  )
  return { categoryData }
}
